using System;
using System.Net.Mail;
using System.Security.Cryptography;
using System.Text;
using SinBiota.Model.Business.AuthenticationServices.Interfaces;
using SinBiota.Model.Entities;


namespace SinBiota.Model.Business.AuthenticationServices.Implementation
{
    public class Authentication : IAuthentication
    {
        public bool VerifyPassword(string typedPassword, User user)
        {
            return (user.Password.Equals(HashedPassword(typedPassword, user.PasswordSalt)));
        }

        public void HashPassword(User user)
        {
            user.PasswordSalt = CreateSalt();
            user.Password = HashedPassword(user.Password, user.PasswordSalt);
        }

        public string CreateSalt()
        {
            return Guid.NewGuid().ToString();
        }
        
        private string HashedPassword(string password, string salt)
        {
            return HashString(password + salt);
        }

        public string HashString(string word)
        {
            return Convert.ToBase64String(new SHA1CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(word)));
            
        }



    }
}